
#pragma once

#include "GActivity.h"
#include "Common/Timer/TimerAxis.h"
#include "Common/Event/Event.h"
#include "Common/EventDefine.h"

//怪物攻城
class GActivityMonsAttackCity : public ITimerHandler, public IEventExecuteSink, public GActivity
{
	enum
	{
		ETimer_ID_Next = 1,
		ETimer_ID_BigBoss = 2,
		ECrystall_AllDie = 3,
		//
		EFreshType_Mons = 1,
		EFreshType_Boss = 2,		
	};
	//区域ID和刷新参数组合的key - AttackMonsCfgInfo
	typedef unordered_map<uint64_t, AttackMonsCfgInfo > AreaMonsDataMap;
public:
	GActivityMonsAttackCity();
	virtual ~GActivityMonsAttackCity();
public:
	virtual void Init(uint32_t activityId);
	virtual void UnInit();
	virtual int32_t	GetType() { return ATI_MONS_ATTACK_CITY; };
	//////////////////////////////////////////////////////////////////////////
	virtual void OnTimer(uint32_t nTimerID);
	//////////////////////////////////////////////////////////////////////////
	virtual void OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	////////////////////////// GActivity ////////////////////////////////////////////////
	virtual bool InitMonsAttackCity(const MonsAttackCityProto &proto);
protected:	
	virtual void	OnActivityStart();
	virtual void	OnActivityStop();
private:
	bool IsCrystalMons(CharIDType cid);				//是否是水晶怪
	bool IsAttackMons(CharIDType cid);				//是否是攻城怪
	Monster *GetCryStalMonster(CharIDType cid);		//获取水晶怪
	Monster *GetAttackMonster(CharIDType cid);		//获取攻城怪
	void SubScribleMonsEvent();						//订阅怪物事件
	bool FreshCrystalMons();						//刷新水晶怪
	void FreshBoxMons();							//刷新宝箱怪
	void FreshPointMons();							//刷新据点怪
	bool InitAttackMons();							//初始化攻击怪
	void FreshAttackMons();							//刷新攻击怪
	void FreshBigBossMons();						//刷新大BOSS怪
	void HideFightNpc();							//隐藏战斗NPC
	void DisplayFightNpc();							//显示战斗NPC
	void OnMonsDie(DieEvent *pDieEvent);			//怪物死亡
	void OnCrystalAllDie();							//水晶怪全部死亡
	void RecycleAllMons();							//回收所有的怪
	void NotifyMonsAttackCityResult(int32_t result);//通知怪物攻城结果
	uint32_t RandAttackMonsAndBoss(int8_t freshType);//随机攻击怪和boss
	void FreshSingleMonsAndBoss(int8_t freshType,int32_t idx,uint32_t areaId, uint32_t lineId); //刷新单个怪和boss



	void Clear();									//清空	
private:
	MonsAttackCityCfg m_cfg;			//活动配置
	int32_t m_averageLevel;				//平均等级
	int32_t m_minLevel;					//最低等级
	int32_t m_maxLevel;					//最高等级
	int32_t m_totalLevDiff;				//总的等级差
	int32_t m_wavePerLevel;				//每个等级多少波怪
	uint32_t m_mapId;					//地图ID
	int32_t m_curLevel;					//当前刷新的等级
	int32_t m_curWave;					//当前怪物波数
	AttackMonsCfgInfo m_curAttackCfg;	//当前刷怪的配置
	AreaMonsDataMap m_mapAreaMonsData;	//区域怪物信息,areaid - AttackMonsCfgInfo	

	//已经刷新的水晶怪
	SET_UINT64 m_setCrystalMons;
	//已经刷新的据点怪
	SET_UINT64 m_setPointMons;
	//已经刷新的攻城怪
	SET_UINT64 m_setAttackMons;
	//战斗NPC
	SET_UINT64 m_setFightNpc;
	
};